//courtesy from Getty.
#include <pthread.h>
#include <stdio.h>

#define NUM_THREADS 20

int total;

void* run_thread(void* arg)
{
  int thread_id;
  thread_id = *((int*)arg);
  printf("Hello from thread %d!\n", thread_id);
  total++;
  return;
}

int main(int argc, char* argv[])
{
  int i;
  pthread_t threads[NUM_THREADS];
  int args[NUM_THREADS];
  for(i = 0; i < NUM_THREADS; i++) {
    args[i] = i;
    pthread_create(&threads[i], 0, run_thread, (void*) &args[i]);
  }

  for(i = 0; i < NUM_THREADS; i++) {
    pthread_join(threads[i], 0);
  }
  printf("%d\n", total);
  return 0;
}
